<template>
  <div class="home-container">
    <van-nav-bar class="page-nav" fixed>
       <van-button
        class="search-btn"
        slot="title"
        type="info"
        size="small"
        round
        icon="search"
        to="/search"
      >搜索</van-button>
</van-nav-bar>
<van-tabs v-model="active" animated swipeable class="channel-tabs">
  <van-tab :title="channel.name" v-for="channel in channels" :key="channel.id" >
    <ArticleList :channel="channel"></ArticleList>
  </van-tab>
     <div slot="nav-right" class="placeholder">
    </div>
    <div slot="nav-right" class="hamburger-btn" @click="showPopup">
        <i class="toutiao toutiao-gengduo" ></i>
    </div>
</van-tabs>
  <van-popup v-model="isChannelEditShow"  closeable position="bottom"
  close-icon="close"  close-icon-position="top-left"
 :style="{ height: '100%' }" class="edit-channel-popup">
 <ChannelEdit :channels='channels' :active="active" @update-active="Fn"></ChannelEdit>
 </van-popup>
  </div>
</template>

<script>
import { getUserChannels } from '@/api/user.js'
import ArticleList from './components/article-list.vue'
import ChannelEdit from './components/channel-edit.vue'
export default {
  components: {
    ArticleList,
    ChannelEdit
  },
  data () {
    return {
      active: 0,
      channels: [],
      isChannelEditShow: false
    }
  },
  created () {
    this.loadChannels()
  },
  methods: {
    async loadChannels () {
      try {
        const res = await getUserChannels()
        console.log(res)
        this.channels = res.data.data.channels
      } catch (err) {
        this.$toast('获取失败')
      }
    },
    showPopup () {
      this.isChannelEditShow = true
    },
    Fn (index, isChannelEditShow) {
      this.active = index
      this.isChannelEditShow = isChannelEditShow
    }
  }
}
</script>

<style scoped lang="less">
.placeholder {
  flex-shrink: 0;
  width: 66px;
  height: 82px;
}
  .home-container {
    padding-top: 180px;
    padding-bottom: 100px;
   /deep/.van-nav-bar__title {
    max-width: unset;
  }
  .search-btn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;
    .van-icon {
      font-size: 32px;
    }
  }
  /deep/ .channel-tabs {
.van-tab {
  border-right: 1px solid #EDEFF3;
  min-width: 200px;
  height: 80px;
  .van-tab__text {
    font-size: 27px;
    color: #777777;
  }
}

.van-tab--active .van-tab__text{
  color: #333 !important;
}
.van-tabs__line {
  width:31px !important;
  height:6px;
  background:rgba(50,150,250,1);
  border-radius:3px;
  bottom: 8px;
}
.van-tabs__wrap {
  position: fixed;
  top: 92px;
  z-index: 2;
  left: 0;
  right: 0;
}
.van-tabs__nav {
  padding: 0;
}
}
.hamburger-btn {
  position: fixed;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 66px;
  height: 82px;
  background-color: #fff;
  opacity: 0.902;
  i.toutiao {
    font-size: 33px;
  }
    &:before {
    content: "";
    position: absolute;
    left: 0;
    width: 1px;
    height: 100%;
    background-image: url(~@/assets/gradient-gray-line.png);
    background-size: contain;
  }
}
.edit-channel-popup {
  padding-top: 100px;
box-sizing: border-box;
}
}
</style>
